﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;

public partial class Orderdaochu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select GID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌,SWID as 仓库编号,SQuantity as 现有数量,SbaseLine as 数量下限,STopLine as 数量上限,GProvider1 as 主供应商,GProvider2  as 次供应商 from Goods , Store where Goods.GID=Store.SGID";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        //GridView1.DataKeyNames = new string[] { "货品编号" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();
        myConn.Close();
        Response.ClearContent();
        //Response.BufferOutput = true;
        ////设定输出的字符集
        //Response.Charset = "GB2312";
        //假定导出的文件名为FileName.xls
        Response.AppendHeader("Content-Disposition", "attachment;filename=库存信息.xls");
        //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        //设置导出文件的格式
        Response.ContentType = "application/ms-excel";
        ////关闭ViewState
        //EnableViewState = false;
        //System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
        //System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
        //System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
        //把HTML写回浏览器
        Response.Write(sw.ToString());
        Response.End();
    }
    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    public override void VerifyRenderingInServerForm(Control control)
    {

    }
}